package com.jd.jr.insights.dm.dim.dao.impl;

import com.jd.jr.insights.dm.dim.dao.OperationLogDao;
import com.jd.jr.insights.dm.dim.dao.model.JfDimOperationLog;
import com.jd.jr.insights.dm.dim.domain.OperationLog;
import com.jd.jr.insights.dm.dim.util.easyui.paginate.Pagger;
import com.jd.jr.insights.dm.dim.util.easyui.paginate.PaggerForEasyUI;
import com.jfinal.plugin.activerecord.Page;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by Administrator on 2017/9/3.
 */
public class OperationLogDaoImpl implements OperationLogDao{
    public Boolean save(OperationLog operationLog) {
        JfDimOperationLog daoa=new  JfDimOperationLog();
        daoa.setErp(operationLog.getErp());
        daoa.setOperateType(operationLog.getOperateType());
        daoa.setBeforeDetail(operationLog.getBeforeDetail());
        daoa.setAfterDetail(operationLog.getAfterDetail());
        daoa.setCreatedTime(new Date());
        daoa.setUpdatedTime(new Date());

        Boolean result=daoa.save();

        return result;
    }
    public Pagger getListInPage(int pageNum) {


        Page page= JfDimOperationLog.dao.paginate(pageNum, Pagger.PAGE_SIZE,"select * ","from jf_dim_operation_log where  1=? order by log_id desc ",1);


        List<OperationLog> operationLogs=new ArrayList<OperationLog>(page.getList().size());

        Iterator<JfDimOperationLog> inter=page.getList().iterator();
        while(inter.hasNext()) {
            JfDimOperationLog jfDimOperationLog = inter.next();



            OperationLog operationLog = new OperationLog(jfDimOperationLog.getLogId(),
                    jfDimOperationLog.getErp(),
                    jfDimOperationLog.getOperateType(),
                    jfDimOperationLog.getBeforeDetail(),
                    jfDimOperationLog.getAfterDetail(),
                    jfDimOperationLog.getCreatedTime(),
                    jfDimOperationLog.getUpdatedTime()

            );
            operationLogs.add(operationLog);
        }
        return  new PaggerForEasyUI(page.getTotalRow(),page.getTotalPage(),pageNum,operationLogs);
    }
}
